import { errLog } from "../../../../util/log";
import { jobHeal } from "../../../../job/heal";
import { getMaxEnergy, spawnCreep } from "../../../../role/spawn";
import { GroupTerminal } from "../../terminal_group";

export class GroupHealers extends GroupTerminal{
    get maxSize(){
        return 2;
    }
    serialize(){
        return {
            super: super.serialize(),
        }
    }
    deserialize(obj){
        super.deserialize(obj.super);
        return this;
    }
    spawn(){
        let newCreep = spawnCreep(this.spawnRoom,{
            require: [MOVE, HEAL],
            move: .50,
            heal: .50,
        },{
            memory: {
                role: 'healer',
            }
        }, getMaxEnergy(this.spawnRoom));
        if(!(newCreep instanceof Creep)){
            return newCreep;
        }
        this.addCreep(newCreep);
        return OK;
    }
    /**
     * 
     * @param {AnyCreep[]} targets 
     */
    run(targets){
        targets = targets.filter((target)=>{
            return target.my &&
                target.hits<target.hitsMax;
        });
        for(let creep of this.creeps){
            try{
                jobHeal.run(creep, targets);
            }catch(e){
                errLog(e);
            }
        }
    }
}